package com.example.day09_7_9_2;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import com.example.day09_7_9_2.base.BaseActivity;
import com.example.day09_7_9_2.bean.DataBean;
import com.example.day09_7_9_2.databinding.ActivityMainBinding;
import com.example.day09_7_9_2.presenter.MPresenter;
import com.example.day09_7_9_2.view.MView;

import java.util.List;

public class MainActivity extends BaseActivity<MPresenter> implements View.OnClickListener, MView {
    private ActivityMainBinding root;

    @Override
    protected MPresenter initPresenter() {
        return new MPresenter();
    }

    @Override
    public View getLayout() {
        root = ActivityMainBinding.inflate(LayoutInflater.from(this));
        return root.getRoot();
    }

    @Override
    public void initView() {
        root.tv.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv:
                mPersenter.getData();
                Log.i("TAG", "onClick: ");
                break;
            default:
                break;
        }
    }

    @Override
    public void succeed(DataBean bean) {
        Log.i("TAG", "succeed: " + bean.toString());
        List<DataBean.ResultsBean> results = bean.getResults();
        Log.i("TAG", "succeed: " + results.size());
        for (int i = 0; i < results.size(); i++) {
            Log.i("111", "succeed: " + results.get(i).toString());
        }
    }

    @Override
    public void failed(String error) {

    }

}
